| Conditions | 2 | 
| Paths | 4 | 
| Total Lines | 53 | 
| Lines | 53 | 
| Ratio | 100 % | 
| Changes | 3 | ||
| Bugs | 0 | Features | 0 | 
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var _ = require('lodash'); | 
            ||
| 21 | View Code Duplication | var _createTestWallet = function(identifier, passphrase, primaryMnemonic, backupMnemonic, segwit, cb) { | 
            |
| 
                                                                                                    
                        
                         | 
                |||
| 22 | var keyIndex = 9999;  | 
            ||
| 23 | var network = client.testnet ? bitcoin.networks.testnet : bitcoin.networks.bitcoin;  | 
            ||
| 24 | |||
| 25 | var primarySeed = bip39.mnemonicToSeed(primaryMnemonic, passphrase);  | 
            ||
| 26 | var primaryPrivateKey = bitcoin.HDNode.fromSeedBuffer(primarySeed, network);  | 
            ||
| 27 | |||
| 28 | var backupSeed = bip39.mnemonicToSeed(backupMnemonic, "");  | 
            ||
| 29 | var backupPrivateKey = bitcoin.HDNode.fromSeedBuffer(backupSeed, network);  | 
            ||
| 30 | var backupPublicKey = backupPrivateKey.neutered();  | 
            ||
| 31 | |||
| 32 | var checksum = primaryPrivateKey.getAddress();  | 
            ||
| 33 | var primaryPublicKey = primaryPrivateKey.deriveHardened(keyIndex).neutered();  | 
            ||
| 34 | |||
| 35 | client.storeNewWalletV1(  | 
            ||
| 36 | identifier,  | 
            ||
| 37 | [primaryPublicKey.toBase58(), "M/" + keyIndex + "'"],  | 
            ||
| 38 | [backupPublicKey.toBase58(), "M"],  | 
            ||
| 39 | primaryMnemonic,  | 
            ||
| 40 | checksum,  | 
            ||
| 41 | keyIndex,  | 
            ||
| 42 | segwit  | 
            ||
| 43 |     ).then(function(result) { | 
            ||
| 44 |         var blocktrailPublicKeys = _.mapValues(result.blocktrail_public_keys, function(blocktrailPublicKey) { | 
            ||
| 45 | return bitcoin.HDNode.fromBase58(blocktrailPublicKey[0], network);  | 
            ||
| 46 | });  | 
            ||
| 47 | |||
| 48 | var wallet = new blocktrail.Wallet(  | 
            ||
| 49 | client,  | 
            ||
| 50 | identifier,  | 
            ||
| 51 | blocktrail.Wallet.WALLET_VERSION_V1,  | 
            ||
| 52 | primaryMnemonic,  | 
            ||
| 53 | null,  | 
            ||
| 54 | null,  | 
            ||
| 55 |             {keyIndex: primaryPublicKey}, | 
            ||
| 56 | backupPublicKey,  | 
            ||
| 57 | blocktrailPublicKeys,  | 
            ||
| 58 | keyIndex,  | 
            ||
| 59 | result.chain || 0,  | 
            ||
| 60 | result.segwit || 0,  | 
            ||
| 61 | client.testnet,  | 
            ||
| 62 | checksum  | 
            ||
| 63 | );  | 
            ||
| 64 | |||
| 65 |         wallet.unlock({ | 
            ||
| 66 | passphrase: passphrase  | 
            ||
| 67 |         }, function(err) { | 
            ||
| 68 | cb(err, wallet);  | 
            ||
| 69 | });  | 
            ||
| 70 |     }, function(err) { | 
            ||
| 71 | cb(err);  | 
            ||
| 72 | });  | 
            ||
| 73 | };  | 
            ||
| 74 | |||
| 118 |